<!-- 卡片>接入单位和报警单位 -->
<template>
    <div class="columnChart-cardNum">
        <div class="contain">
            <div class="left" @click="openUnitList(1)">
                <div class="left-img">
                    <img src="@/assets/images/homeLeft/access-unit-build.png" alt="accessUnitSrc" />
                </div>
                <div class="right-text">
                    <div class="tittle">接入单位</div>
                    <div class="number">{{accessUnitNumber}}</div>
                </div>
            </div>
            <div class="left right" @click="openUnitList(2)">
                <div class="left-img">
                    <img src="@/assets/images/homeLeft/alarm-unit-build.png" alt="accessUnitSrc" />
                </div>
                <div class="right-text">
                    <div class="tittle">报警单位</div>
                    <div class="number">{{alarmUnitNumber}}</div>
                </div>
            </div>
        </div>
        <div class="open-unit-list" v-show="isOpen">
            <div class="open-unit-list-top">
                <span class="tittle">{{ openListTittle }}</span>
                <span class="close" @click="closeUnitList"></span>
            </div>
            <div class="open-unit-list-container">
                <div class="open-unit-list-search">
                    <i class="search-icon"></i>
                    <el-input
                        v-model="unitText"
                        placeholder="请输入内容"
                        class="search-input"
                        @keyup.enter.native="getOrgList()"
                    ></el-input>
                </div>
                <div class="open-unit-items">
                    <template v-if="openListArr">
                        <div class="item" v-for="(item,index) in openListArr" :key="index">
                            <span class="logo-pic">
                                <el-image
                                    fit="cover"
                                    :src="item.logo">
                                    <div slot="error" class="image-slot">
                                        <i class="el-icon-picture-outline"></i>
                                    </div>
                                </el-image>
                            </span>
                            <!-- 列表点击跳转单单位 -->
                            <div
                                class="name"
                                :class="(faultType?'red':'')"
                                @click="$Ctl.enterSingleHome({orgId:item.orgId},1)"
                            >{{ item.orgName }}</div>
                            <span class="number">{{ index+1 }}</span>
                        </div>
                    </template>
                    <div v-else class="text-align-center">
                        <img :src="this.GLOBAL.defultDataSrc" alt="">
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { getOrgAllCount, getOrgsStatusList } from '@/api/organization'
export default {
    data () {
        return {
            accessUnitNumber: 0, // 接入单位
            alarmUnitNumber: 0, // 报警单位
            isOpen: false,
            openListTittle: '接入单位列表',
            openListArr: [],
            faultType: '',
            unitText: '',
            isMuilUnitUser: this.$store.state.userInfo.isMuilUnitUser// 0:单单位用户;1:多单位用户
        }
    },
    created () {
        let that = this

        window.FunList.openUnitList = that.openUnitList
        window.FunList.closeUnitList = that.closeUnitList
        that.getUnitNumber()

        if (that.isMuilUnitUser) { // 推送只推一级首页
            window.FunList.alertUnitNum_ws = function (wsData) {
                that.alarmUnitNumber = wsData.count
                if (that.isOpen) {
                    that.getOrgList()
                }
            }
        }
    },
    methods: {
        // 获取接入单位统计
        getUnitNumber () {
            let that = this
            getOrgAllCount({
                orgIds: that.$store.state.userInfo.organizationIds,
                countTypes: '5,13'
            }).then(res => {
                if (res.status === 200) {
                    that.accessUnitNumber = res.data.joinUpCount
                    that.alarmUnitNumber = res.data.fireAlarmOrgCount
                }
            })
        },
        // 获取接入单位列表
        getOrgList () {
            let that = this
            // that.$Ctl.loading(1, 10000)
            getOrgsStatusList({
                orgIds: that.$store.state.userInfo.organizationIds,
                faultType: that.faultType,
                orgName: that.unitText
            }).then(res => {
                that.openListArr = res.data.orgDetail || []
                // that.$Ctl.loading(0)
            })
        },
        // 展开列表
        openUnitList (type) {
            let that = this
            if (type === 1) {
                that.faultType = ''
                that.openListTittle = '接入单位列表'
            } else {
                that.faultType = 10
                that.openListTittle = '报警单位列表'
            }
            if (!that.isOpen) {
                that.isOpen = true
                let newArr = []
                let arr = that.bsConfig.LeftMenu.cards // 获取全局的菜单配置
                // 遍历卡片配置，将其他的高度设为0,
                for (let i = 0; i < arr.length; i++) {
                    let obj = $.extend({}, arr[i])
                    if (arr[i].id === 'CardUnitNum') {
                        obj.height = '85%'
                    } else {
                        if (arr[i].id !== 'CardLogo') {
                            if (arr[i].id !== 'CardTools') {
                                obj.height = '0'
                            }
                        }
                    }
                    newArr.push(obj)
                }
                // 通知父组件卡片组发生变化
                that.$emit('isOpenUnitList', newArr)
            }
            that.getOrgList()
        },
        closeUnitList: function () {
            let that = this
            that.isOpen = false
            // 通知父组件卡片组发生变化
            that.$emit('isOpenUnitList', that.bsConfig.LeftMenu.cards)
        }
    }
}
</script>
<style rel="stylesheet/scss" lang="scss">
.columnChart-cardNum {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    font-size: 16px;
    .contain {
        width: 100%;
        min-height: 122px;
        display: flex;
        flex-direction: row;
        justify-content: center;
        align-items: center;
        .left {
            width: 50%;
            float: left;
            cursor: pointer;
            .left-img {
                position: relative;
                width: 75px;
                height: 75px;
                float: left;
                background: url(../../assets/images/homeLeft/access-unit.png) center center no-repeat;
                background-size: contain;
                img {
                    position: absolute;
                    top: 14%;
                    left: 18%;
                    width: 70%;
                    height: 70%;
                }
                &:hover img {
                    animation: unit-jump .5S linear infinite;
                }
            }
            .right-text {
                padding: 5px 10px;
                display: inline-flex;
                justify-content: center;
                flex-direction: column;
                align-items: flex-start;
                .tittle {
                    color: #a3bedd;
                    font-size: 1.125em;
                }
                .number {
                    color: #3c83f6;
                    font-size: 2em;
                    line-height: 1.5em;
                    font-family: 'DigitaldreamFat';
                }
            }
        }
        .right {
            cursor: pointer;
            .left-img {
                background: url(../../assets/images/homeLeft/alarm-unit.png) center center no-repeat;
                background-size: contain;
            }
            .right-text {
                .number {
                    color: #cd3350;
                }
            }
        }
    }
    .open-unit-list {
        width: 100%;
        height: 92%;
        .open-unit-list-top {
            margin: 8px 0;
            font-size: 18px;
            .tittle,
            .close {
                color: #51a6fa;
            }
            .close {
                float: right;
                cursor: pointer;
                width: 13px;
                height: 13px;
                background: url(../../assets/images/homeLeft/close.png) 0 0
                    no-repeat;
                background-size: cover;
                margin-top: 6px;
            }
        }
        .open-unit-list-container {
            width: 100%;
            height: calc(100% - 35px);
            .open-unit-list-search {
                width: 100%;
                height: 40px;
                margin: 15px 0;
                background: url(../../assets/images/homeLeft/search-bg.png) 0 0
                    no-repeat;
                background-size: 100% 100%;
                position: relative;
                .search-icon {
                    width: 20px;
                    height: 20px;
                    background: url(../../assets/images/homeLeft/search.png) 0 0
                        no-repeat;
                    background-size: 100% 100%;
                    position: absolute;
                    left: 20px;
                    top: 10px;
                }
                .search-input {
                    width: 100%;
                    height: 100%;
                    padding-left: 12%;
                    outline: none;
                    .el-input__inner {
                        background-color: rgba(255, 255, 255, 0);
                        border: none;
                        color: #fff;
                    }
                    input::-webkit-input-placeholder{
                    color:#505961;
                    }
                    input::-moz-placeholder{   /* Mozilla Firefox 19+ */
                    color:#505961;
                    }
                    input:-moz-placeholder{    /* Mozilla Firefox 4 to 18 */
                    color:#505961;
                    }
                    input:-ms-input-placeholder{  /* Internet Explorer 10-11 */
                    color:#505961;
                    }
                }
            }
            .open-unit-items {
                width: 100%;
                height: calc(100% - 60px);
                overflow-y: auto;
                .item {
                    width: 98%;
                    height: 40px;
                    display: flex;
                    flex-direction: row;
                    align-items: center;
                    margin-bottom: 8px;
                    position: relative;
                    padding: 0 3%;
                    .logo-pic {
                        .el-image {
                            width: 25px;
                            height: 25px;
                            border-radius: 5px;
                            margin-top: 5px;
                        }
                    }
                    .name {
                        color: #fff;
                        font-size: 18px;
                        padding-left: 15px;
                        cursor: pointer;
                        &.red {
                            color: #cd3350;
                        }
                    }
                    .number {
                        color: #fff;
                        font-size: 18px;
                        position: absolute;
                        right: 5px;
                    }
                }
            }
        }
    }
}
</style>
